package com.shiguiwu.springboot3.kafka.partition;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @description: 自定义分区，可以根据规则路由到哪个分区
 * @author: stone
 * @date: Created by 2023/11/13 17:53
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.kafka.partition
 */
@Slf4j
public class CustomizePartitioner  implements Partitioner {
    @Override
    public int partition(String s, Object o, byte[] bytes, Object o1, byte[] bytes1, Cluster cluster) {
        //自定义分区规则，默认全部发送到0号分区
        log.error("自定义分区规则=====");
        return 0;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
